import apiClient from "../../apiClient";

import type { UserInfo } from "#/entity";

//登录请求
export interface SignInReq {
	username: string;
	password: string;
}

export enum UserApi {
	SignIn = "/login",
	Logout = "/logout",
	User = "/sys/user/queryUserInfo",
	PageList = "/sys/user/list",
}

export interface PageListReq {
	account?: string;
	name?: string;
	status?: string;
	roleId?: number | string;
	page: number;
	pageSize: number;
}
export interface PageListRes {
	total: number;
	records: UserInfo[];
}

const signin = (data: SignInReq) => apiClient.post<UserInfo>({ url: UserApi.SignIn, data });
const logout = () => apiClient.get({ url: UserApi.Logout });
const findById = (id: string) => apiClient.get<UserInfo>({ url: `/sys/user/queryUserInfo/${id}` });
const pageList = (data: PageListReq) => apiClient.post<PageListRes>({ url: UserApi.PageList, data });
const add = (data: UserInfo) => apiClient.post<UserInfo>({ url: "/sys/user/add", data });
const update = (data: UserInfo) => apiClient.post<UserInfo>({ url: "/sys/user/updateUserinfo", data });
const deleteUser = (ids: string[]) => apiClient.delete({ url: "/sys/user/del", params: { ids: ids.join(",") } });
const editPwd = (data: UserInfo) => apiClient.post({ url: "/sys/user/editPwd", data: data });

const roleUserPageList = (data: PageListReq) => apiClient.post<PageListRes>({ url: "/sys/user/role/page", data});

export default {
	signin,
	findById,
	logout,
	pageList,
	add,
	update,
	deleteUser,
	editPwd,
	roleUserPageList
};
